﻿namespace T.FAS.Runtime.DataAccess.Common
{
    public class ExceptionManage
    {
        public static string LineFeedSymbol
        {
            get
            {
                return "<br />";
                return "\r\n";
            }
        }
        private const string ErrorPrefix = "Dae-";
        private const string ErrorPrefix_Conn = "Conn";
        private const string ErrorPrefix_CRUD = "CRUD";

        public class DM
        {
            #region 获取DM错误
            public const string ErrorCode_DM = ErrorPrefix + "DM-";
            /// <summary>
            /// 获取DM时，出现错误
            /// </summary>
            public const string ErrorCode_DM_Error = ErrorCode_DM + "Error";

            /// <summary>
            /// 获取DM时，内存缓存错误
            /// </summary>
            public const string ErrorCode_DM_Memo = ErrorCode_DM + "Memo";

            /// <summary>
            /// 获取DM时，参数有错误
            /// </summary>
            public const string ErrorCode_DM_Para = ErrorCode_DM + "Para";

            /// <summary>
            /// 获取DM时，Redis缓存错误
            /// </summary>
            public const string ErrorCode_DM_Redis = ErrorCode_DM + "Redis";

            /// <summary>
            /// 获取DM时，Redis缓存错误
            /// </summary>
            public const string ErrorCode_DM_Redis_Conn = ErrorCode_DM_Redis + "-" + ErrorPrefix_Conn;

            /// <summary>
            /// 获取DM时，HSF服务错误
            /// </summary>
            public const string ErrorCode_DM_HSF = ErrorCode_DM + "HSF";

            /// <summary>
            /// 获取DM时，操作DB错误
            /// </summary>
            public const string ErrorCode_DM_DB = ErrorCode_DM + "DB";

            /// <summary>
            /// 获取DM时，操作DB错误
            /// </summary>
            public const string ErrorCode_DM_DB_Conn = ErrorCode_DM_DB + "-" + ErrorPrefix_Conn;

            /// <summary>
            /// 获取DM时，MyBatis错误
            /// </summary>
            public const string ErrorCode_DM_DB_MyBatis = ErrorCode_DM_DB + "MyBatis";

            /// <summary>
            /// 获取DM时，MyBatis错误
            /// </summary>
            public const string ErrorCode_DM_DB_SQL = ErrorCode_DM_DB + "SQL";

            /// <summary>
            /// 获取DM时，构建模型关系错误
            /// </summary>
            public const string ErrorCode_DM_Build = ErrorCode_DM + "Build";
            #endregion
        }

        public class CRUD
        {
            #region 按CRUD操作分类的错误

            /// <summary>
            /// CRUD错误
            /// </summary>
            private const string ErrorCode_CRUD = ErrorPrefix + ErrorPrefix_CRUD;

            public const string ParaError = ErrorCode_CRUD + "-Para";

            public static CRUDBase Create
            {
                get
                {
                    return CRUDFactory.ERROR("C");
                }
            }

            public static CRUDBase Retrive
            {
                get
                {
                    return CRUDFactory.ERROR("R");
                }
            }

            public static CRUDBase Update
            {
                get
                {
                    return CRUDFactory.ERROR("U");
                }
            }

            public static CRUDBase Delete
            {
                get
                {
                    return CRUDFactory.ERROR("D");
                }
            }
            #endregion

            class CRUDFactory
            {
                private static C c = new C();
                private static R r = new R();
                private static U u = new U();
                private static D d = new D();
                public static CRUDBase ERROR(string key)
                {
                    switch (key)
                    {
                        case "C": return c;
                        case "R": return r;
                        case "U": return u;
                        case "D": return d;
                    }
                    return null;
                }
            }

            public class CRUDBase
            {
                protected virtual string key { get; }
                public string FuncPara { get { return key + "FuncPara"; } }
                public string Context { get { return key + "Context"; } }
                public string Build { get { return key + "Build"; } }
                public string SQLPara { get { return key + "SQLPara"; } }
                public string Exec { get { return key + "Exec"; } }
            }

            class C : CRUDBase
            {
                protected override string key { get { return "C"; } }
            }
            class R : CRUDBase
            {
                protected override string key { get { return "R"; } }
            }
            class U : CRUDBase
            {
                protected override string key { get { return "U"; } }
            }
            class D : CRUDBase
            {
                protected override string key { get { return "D"; } }
            }
        }
    }

}
